﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security;

namespace PasswordProvider.ViewModel.Framework
{
    /// <summary>
    /// Encapsulates data for a password box view. Inherits from VisualViewModel and provides
    /// the property Password (SecureString).
    /// </summary>
    public class PasswordEntryViewModel : VisualViewModel
    {
        internal event ValueChangedEventHandler<SecureString> PasswordChanged;

        internal PasswordEntryViewModel() { }

        internal PasswordEntryViewModel(string displayName)
            : base(displayName)
        {
        }

        public SecureString Password
        {
            get 
            {
                if (_password == null)
                {
                    _password = new SecureString();                    
                }
                return _password; 
            }
            set
            {
                if (SetPropertyValue(value, ref _password, "Password"))
                {
                    if (PasswordChanged != null)
                        PasswordChanged(value);
                }

            }
        } private SecureString _password;
    }
}
